﻿Public Class SettingProfile
    Inherits baseForm
    Dim param As String() = New String() {"p_nama", "p_alamat", "p_telepon"}
    Function getValueCtl(ByVal value As String) As Object
        Dim ctl() As Control
        Dim strval As Object
        strval = ""
        ctl = Me.Controls.Find(value, True)
        If ctl.Length > 0 Then
            If TypeOf ctl(0) Is TextBox Then
                Dim txb As TextBox = CType(ctl(0), TextBox)
                strval = txb.Text
            End If
        End If
        Return strval
    End Function
    Function setparam(ByVal opt As String) As Object()
        Dim liststr As New List(Of String)
        liststr.Add(opt)
        For Each obj As String In param
            liststr.Add(getValueCtl(obj))
        Next
        
        Return liststr.ToArray()
    End Function
    Private Sub initProfile()
        Dim dt As New DataTable
        If Utils.executeSP("proc_profil", setparam("load"), dt) Then
            If Utils.RowExist(dt) Then
                TextNamaProfil.Text = dt.Rows(0)(0)
                TextAlamatProfil.Text = dt.Rows(0)(1)
                TextTelponProfil.Text = dt.Rows(0)(2)
            End If
        End If
    End Sub

    Function validasi() As Boolean
        Dim retval As Boolean = True
        For Each ctl As Control In Me.Controls
            If TypeOf ctl Is TextBox Then
                If ctl.Text = "" Then
                    retval = False
                    Exit For
                End If
            End If
        Next
        Return retval
    End Function
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If validasi() Then
            If Utils.exec_SP("proc_profil", setparam("ins")) Then
                Utils.getmessagesystem(0, "Data Berhasil Disimpan")
            End If
        Else
            Utils.getmessagesystem(1, "Data Entri Belum Lengkap!!")
        End If
    End Sub

    Private Sub SettingProfile_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        initProfile()
    End Sub
End Class
